//很多配置vue-cli已经配置好了，需要自定义在vue.config.js里修改
module.exports={
  //webpack提供的配置项configureWebpack
  configureWebpack:{
    devServer:{
      port:8089,
      open:true,
      //Mock数据
      //配置文件的修改需要重启项目
      before(app){
        // app.get('请求地址',(req,res)=>{
        //   res.json({
            
        //   })
        // })
        //注册接口
        //用户信息池
        let userpoor=[
          {username:'zs', password: '123'},
          {username: 'ls', password: '123'}
        ]
        app.get('/api/register',(req,res)=>{
          //es6解构赋值
          const { username, password}=req.query
          const userlength = userpoor.filter(v=>v.username==username).length
          if(userlength>0){
            res.json({
              success: false,
              message: '用户名已存在'
            })
          }else{
            res.json({
              success: true,
              message: '注册成功 '
            })
          }
        })
        //登录接口
        let tokenkey='wanrenmi'
        app.get('/api/login',(req,res)=>{
          const {username,password}=req.query
          if(username == 'zs' && password == '123' || username == 'ls' && password == '123'){
            res.json({
              code: 0,
              message: '登录成功',
              token: tokenkey+'-'+username+'-'+(new Date().getTime()+60*60*1000)
            })
          }else{
            res.json({
              code: 1,
              message: '账号或密码错误'
            })
          }
        })
      }
    }
  },

  css: {
    loaderOptions: {
      stylus: {
        'resolve url': true,
        'import': [
          './src/theme'
        ]
      }
    }
  },

  pluginOptions: {
    'cube-ui': {
      postCompile: true,
      theme: true
    }
  }
}
